<?php
/**
 * /index.php	-	san-pham-moi-nhat.html
 * /team/index.php	-	san-pham-gan-day.html
 * /help/tour.php	-	huong-dan-mua-hang.html
 * /forum/index.php	-	binh-luan.html
 * 
 * Enter description here ...
 */
function current_frontend() {
	global $INI;
	$a = array(
			'/san-pham-moi-nhat.html' => 'Sản phẩm hôm nay',
			'/san-pham-gan-day.html' => 'Sản phẩm gần đây',
			'/help/huong-dan-mua-hang.html' => 'Hướng dẫn mua hàng',
			'/forum/binh-luan.html' => 'Bình luận',
			//'/help/faqs.php' => 'Hỏi đáp',
			);
	if(option_yes('navforum')) $a['/forum/binh-luan.html'] = 'Bình luận';
	$r = $_SERVER['REQUEST_URI'];
	if (preg_match('#/team#',$r)) $l = '/team/index.php';
	elseif (preg_match('#/help#',$r)) $l = '/help/tour.php';
	elseif (preg_match('#/subscribe#',$r)) $l = '/subscribe.php';
	else $l = '/index.php';
	return current_link(null, $a);
}
function current_backend() {
	global $INI;
	$a = array(
			'/manage/misc/index.php' => 'Panel',
			'/manage/team/index.php' => 'Offer',
			'/manage/order/index.php' => 'Orders',
			'/manage/coupon/index.php' => 'Coupons',
			'/manage/user/index.php' => 'Users',
			'/manage/market/index.php' => 'Marketing',
			'/manage/category/index.php' => 'Categories',
			'/manage/vote/index.php' => 'Vote',
			'/manage/credit/index.php' => 'Credits',
			'/manage/bank/index.php'=>'Bank alert',
			'/manage/system/index.php' => 'System',
			);
	$r = $_SERVER['REQUEST_URI'];
	if (preg_match('#/manage/(\w+)/#',$r, $m)) {
		$l = "/manage/{$m[1]}/index.php";
	} else $l = '/manage/misc/index.php';
	return current_link($l, $a);
}
function current_biz() {
	global $INI;
	$a = array(
			'/biz/index.php' => 'Trang chủ',
			'/biz/settings.php' => 'Cấu hình',
			'/biz/coupon.php' => 'Danh sách phiếu giảm giá',
			'/biz/voucherserial.php' => 'Voucher serial',
			);
	$r = $_SERVER['REQUEST_URI'];
	if (preg_match('#/biz/coupon#',$r)) $l = '/biz/coupon.php';
	elseif (preg_match('#/biz/settings#',$r)) $l = '/biz/settings.php';
	elseif (preg_match('#/biz/voucherserial#',$r)) $l = '/biz/voucherserial.php';
	else $l = '/biz/index.php';
	return current_link($l, $a);
}
function current_forum($selector='index') {
	global $city;
	$a = array(
			'/forum/tat-ca.html' => 'Tất cả',
			'/forum/khu-vuc.html' => "Khu vực {$city['name']}",
			'/forum/thao-luan-chung.html' => 'Thảo luận chung',
			);
	if (!$city) unset($a['/forum/city.php']);
	$l = "/forum/{$selector}.php";
	return current_link($l, $a, true);
}
function current_seller($selector){
	$a	=	array(
		'/hop-tac-kinh-doanh.html'=>'Hợp tác kinh doanh',
		'/thong-tin-doanh-nghiep.html'=>'Thông tin doanh nghiệp',
	);
	$l = "/{$selector}.html";
	return current_link($l, $a, true);
}
function current_invite($selector='refer') {
	$a = array(
			'/account/refer.php' => 'Tất cả',
			'/account/referpending.php' => "Para comprar",
			'/account/referdone.php' => 'Ofertas pagas',
			);
	$l = "/account/{$selector}.php";
	return current_link($l, $a, true);
}

function current_partner($gid='0') {
	$a = array(
			'/partner/index.php' => 'All',
			);
	foreach(option_category('partner') AS $id=>$name) {
		$a["/partner/index.php?gid={$id}"] = $name;
	}
	$l = "/partner/index.php?gid={$gid}";
	if (!$gid) $l = "/partner/index.php";
	return current_link($l, $a, true);
}

function current_city($cename, $citys) {
	$link = "/city.php?ename={$cename}";
	$links = array();
	foreach($citys AS $city) {
		$links["/city.php?ename={$city['ename']}"] = $city['name'];
	}
	return current_link($link, $links);
}

function current_coupon_sub($selector='index') {
	$selector = $selector ? $selector : 'index';
	$a = array(
		'/coupon/index.php' => 'Không sử dụng',
		'/coupon/consume.php' => 'Được sử dụng',
		'/coupon/expire.php' => 'Hết hạn',
	);
	$l = "/coupon/{$selector}.php";
	return current_link($l, $a);
}
/**
 * /coupon/index.php	-	tien-ich.html
 * /order/index.php	-	gio-hang.html
 * /credit/index.php	-	so-du-tai-khoan.html
 * /account/settings.php	-	cai-dat-tai-khoan.html
 * /account/myask.php	-	cau-hoi.html
 * Enter description here ...
 * @param unknown_type $selector
 */
function current_account($selector) {
	global $INI;
	$a = array(
		//'/user/tien-ich.html' => 'Tiện ích ' . $INI['system']['couponname'],
		'/user/gio-hang.html' => 'Giỏ hàng',
		//'/account/refer.php' => 'Minhas invitation',
		//'/user/so-du-tai-khoan.html' => 'Số dư tài khoản',
		'/user/cai-dat-tai-khoan.html' => 'Cài đặt tài khoản',
		'/user/cau-hoi.html' => 'Câu hỏi đã gửi',
	);
	/**
	if (option_yes('usercredit')) {
		$a['/credit/score.php'] = 'My credits';
	}
	**/
	//return current_link($selector, $a, true);
	$l = "/user/{$selector}.html";
	return current_link($l, $a, true);
}
function current_register($selector='index'){
	global $INI;
	$a = array(
		'/user/dang-ky.html'=>'Tài khoản ' . $INI['system']['abbreviation'],
		'/forward.php?openID=google'=>'Google ID',
		'/forward.php?openID=yahoo'=>'Yahoo ID',
		'/tw_connect/redirect.php'=>'Twitter ID',
		'/facebook-client'=>'Facebook ID',
		'/forward.php?openID=aol'=>'AOL ID',
		'/forward.php?openID=myspace'=>'Myspace ID',
		'/forward.php?openID=openid'=>'OpenID',
		'/forward.php?openID=wordpress'=>'Wordpress ID',
	);
	return current_link($l, $a, true);
}
function current_bank($selector='index'){
	$a = array(
	'/manage/bank/index.php'=>'All',
	'/manage/bank/process.php'=>'Processed',
	'/manage/bank/unprocess.php'=>'Un-process',
	);
	$l = "/manage/bank/{$selector}.php";
	return current_link($l, $a, true);
}
function current_about($selector) {
	global $INI;
	$a = array(
		'/us/ve-chung-toi.html' => 'Về ' . $INI['system']['abbreviation'],
		'/us/lien-he.html' => 'Liên hệ',
		'/us/co-hoi-nghe-nghiep.html' => 'Cơ hội nghề nghiệp',
		'/us/dieu-khoan-su-dung.html' => 'Điều khoản sử dụng',
		'/us/chinh-sach-rieng-tu.html' => 'Chính sách riêng tư',
	);
	$l = "/us/{$selector}.html";
	return current_link($l, $a, true);
}

function current_help($selector='faqs') {
	global $INI;
	$a = array(
		'/help/huong-dan-mua-hang.html' => 'Hướng dẫn mua hàng',
		'/help/huong-dan-thanh-toan.html'=>'Hướng dẫn thanh toán',
		'/help/hoi-dap.html' => 'Hỏi/đáp',
		'/help/api/api.html'=>'API'
		//'/help/wroupon.php' => $INI['system']['abbreviation'] . ' là gì?',
	);
	$l = "/help/{$selector}.html";
	return current_link($l, $a, true);
}

function current_order_index($selector='index') {
	$selector = $selector ? $selector : 'index';
	$a = array(
		'/user/gio-hang-tat-ca.html' => 'Tất cả',
		'/user/gio-hang-chua-thanh-toan.html' => 'Chưa thanh toán',
		'/user/gio-hang-da-thanh-toan.html' => 'Đã thanh toán',
	);
	$l = "/order/index.php?s={$selector}";
	return current_link($l, $a);
}

function current_credit_index($selector='index') {
	$selector = $selector ? $selector : 'index';
	$a = array(
		'/credit/score.php' => 'Meus créditos',
		'/credit/goods.php' => 'Converter créditos',
	);
	$l = "/credit/{$selector}.php";
	return current_link($l, $a);
}

function current_link($link, $links, $span=false) {
	$html = '';
	$span = $span ? '<span></span>' : '';
	foreach($links AS $l=>$n) {
		if (trim($l,'/')==trim($link,'/')) {
			$html .= "<li class=\"current\"><a href=\"{$l}\">{$n}</a>{$span}</li>";
		}
		else $html .= "<li><a href=\"{$l}\">{$n}</a>{$span}</li>";
	}
	return $html;
}

/* manage current */
function mcurrent_misc($selector=null) {
	$a = array(
		'/manage/misc/index.php' => 'Panel',
		'/manage/misc/ask.php' => 'Questions',
		'/manage/misc/feedback.php' => 'Contact',
		'/manage/misc/subscribe.php' => 'User',
		'/manage/misc/smssubscribe.php' => 'SMS',
		'/manage/misc/invite.php' => 'Invition',
		'/manage/misc/money.php' => 'Financial',
		'/manage/misc/link.php' => 'Link Friends',
		'/manage/misc/backup.php' => 'Backup',
	);
	$l = "/manage/misc/{$selector}.php";
	return current_link($l,$a,true);
}

function mcurrent_misc_money($selector=null){
	$selector = $selector ? $selector : 'store';
	$a = array(
		'/manage/misc/money.php?s=store' => 'Recarga Offline',
		'/manage/misc/money.php?s=charge' => 'Recarga Online',
		'/manage/misc/money.php?s=withdraw' => 'Registros de Retirada',
		'/manage/misc/money.php?s=cash' => 'Pagar em dinheiro',
		'/manage/misc/money.php?s=refund' => 'Registros de restituição',
	);
	$l = "/manage/misc/money.php?s={$selector}";
	return current_link($l, $a);
}

function mcurrent_misc_backup($selector=null){
	$selector = $selector ? $selector : 'backup';
	$a = array(
		'/manage/misc/backup.php' => 'Backup do banco',
		'/manage/misc/restore.php' => 'Restaurar Banco de dados',
	);
	$l = "/manage/misc/{$selector}.php";
	return current_link($l, $a);
}

function mcurrent_misc_invite($selector=null){
	$selector = $selector ? $selector : 'index';
	$a = array(
		'/manage/misc/invite.php?s=index' => 'Pendentes',
		'/manage/misc/invite.php?s=record' => 'Aprovado',
		'/manage/misc/invite.php?s=cancel' => 'Faltas',
	);
	$l = "/manage/misc/invite.php?s={$selector}";
	return current_link($l, $a);
}
function mcurrent_order($selector=null) {
	$a = array(
		'/manage/order/index.php' => 'Current Offer',
		'/manage/order/pay.php' => 'Pay deals',
		'/manage/order/credit.php' => 'Credit offers',
		'/manage/order/unpay.php' => 'Offers not paid',
		'/manage/voucher/index.php' => 'Voucher Serial',
	);
	if($selector=='voucher')
		$l = "/manage/voucher/index.php";
	else { $l = "/manage/order/{$selector}.php"; } 
	return current_link($l,$a,true);
}

function mcurrent_user($selector=null) {
	$a = array(
		'/manage/user/index.php' => 'Customer List',
		'/manage/user/manager.php' => 'Manager List',
		'/manage/partner/index.php' => 'Partner List',
		'/manage/partner/create.php' => 'New user',
	);
	$l = "/manage/user/{$selector}.php";
	return current_link($l,$a,true);
}
function mcurrent_team($selector=null) {
	$a = array(
		'/manage/team/index.php' => 'Current Offer',
		'/manage/team/success.php' => 'Offer valid',
		'/manage/team/failure.php' => 'Offers void',
		'/manage/team/edit.php' => 'New offer',
	);
	$l = "/manage/team/{$selector}.php";
	return current_link($l,$a,true);
}

function mcurrent_feedback($selector=null) {
	$a = array(
		'/manage/feedback/index.php' => 'Ver todas',
	);
	$l = "/manage/feedback/{$selector}.php";
	return current_link($l,$a,true);
}
function mcurrent_coupon($selector=null) {
	$a = array(
		'/manage/coupon/index.php' => 'Not used',
		'/manage/coupon/consume.php' => 'Used',
		'/manage/coupon/expire.php' => 'Expired',
		'/manage/coupon/card.php' => 'Coupon',
		'/manage/coupon/cardcreate.php' => 'Novo Coupons',
	);
	$l = "/manage/coupon/{$selector}.php";
	return current_link($l,$a,true);
}
function mcurrent_category($selector=null) {
	$zones = get_zones();
	$a = array();
	foreach( $zones AS $z=>$o ) {
		$a['/manage/category/index.php?zone='.$z] = $o;
	}
	$l = "/manage/category/index.php?zone={$selector}";
	return current_link($l,$a,true);
}
function mcurrent_partner($selector=null) {
	$a = array(
		'/manage/user/index.php' => 'Customer List',
		'/manage/user/manager.php' => 'Manage List',
		'/manage/partner/index.php' => 'Partner List',
		'/manage/partner/create.php' => 'New user',
	);
	$l = "/manage/partner/{$selector}.php";
	return current_link($l,$a,true);
}
function mcurrent_market($selector=null) {
	$a = array(
		'/manage/market/index.php' => 'Email marketing',
		'/manage/market/sms.php' => 'SMS group',
		'/manage/market/down.php' => 'Download',
	);
	$l = "/manage/market/{$selector}.php";
	return current_link($l,$a,true);
}
function mcurrent_market_down($selector=null) {
	$a = array(
		'/manage/market/down.php' => 'Cell Number',
		'/manage/market/downemail.php' => 'Email',
		'/manage/market/downorder.php' => 'Sort deal',
		'/manage/market/downcoupon.php' => 'Coupon',
		'/manage/market/downuser.php' => 'User info',
	);
	$l = "/manage/market/{$selector}.php";
	return current_link($l,$a,true);
}

function mcurrent_system($selector=null) {
	$a = array(
		'/manage/system/index.php' => 'Basic',
		'/manage/system/option.php' => 'Setting',
		'/manage/system/bulletin.php' => 'Notices',
		'/manage/system/pay.php' => 'Payment',
		'/manage/system/email.php' => 'Email',
		'/manage/system/sms.php' => 'SMS',
		'/manage/system/bank.php'=>'Bank',
		'/manage/system/page.php' => 'Pages',
		'/manage/system/cache.php' => 'Cache',
		'/manage/system/skin.php' => 'Skin',
		'/manage/system/template.php' => 'Template',
		'/manage/system/upgrade.php' => 'Update',
	);
	$l = "/manage/system/{$selector}.php";
	return current_link($l,$a,true);
}

function mcurrent_credit($selector=null) {
	$a = array(
		'/manage/credit/index.php' => 'Credit records',
		'/manage/credit/settings.php' => 'Credit Lines',
		'/manage/credit/goods.php' => 'Convert Credits',
	);
	$l = "/manage/credit/{$selector}.php";
	return current_link($l,$a,true);
}
